<template>
  <div>
    <h1>疾病管理</h1>
    <el-button type="text" @click="ailments()">新增/修改</el-button>
    <el-card>
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          prop="ailmentId"
          label="因素id"
          width="180">
        </el-table-column>
        <el-table-column
          prop="ailmentName"
          label="疾病名称"
          width="180">
        </el-table-column>
        <el-table-column
          label="操作"
          width="180">
          <template slot-scope="scope">
            <el-button @click="ailmentDeleted(scope.row.ailmentId)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose">
        <el-form :model="tbAilment" status-icon ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="请输入疾病id">
            <el-input v-model="tbAilment.ailmentId"></el-input>
          </el-form-item>
          <el-form-item label="请输入疾病名称">
            <el-input v-model="tbAilment.ailmentName"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="ailmentInsert()">新增</el-button>
            <el-button type="primary" @click="ailmentUpdate()">修改</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
  import { ailmentSelect,ailmentUpdate,ailmentInsert,ailmentDeleted } from '@/api/evaluating'
  export default {
    name: 'index',
    data() {
      return {
        dialogVisible: false,
        tbAilment:{
          ailmentId:'',
          ailmentName:'',
        },
        tableData: []
      }
    },
    mounted(){
      this.ailmentSelect()
    },
    methods:{
      ailments(){
        this.dialogVisible=true
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
      ailmentSelect(){
        console.log(this.tbAilment)
        ailmentSelect(this.tbAilment).then((res)=>{
          this.tableData=res.data
        })
      },
      ailmentUpdate(){
        console.log(this.tbAilment)
        ailmentUpdate(this.tbAilment).then((res)=>{
          console.log(res.data)
          this.tbAilment=[]
          this.dialogVisible=false
          this.ailmentSelect()
        })
      },
      ailmentInsert(){
        this.tbAilment.ailmentId=null
        ailmentInsert(this.tbAilment).then((res)=>{
          this.dialogVisible=false
          this.ailmentSelect()
        })
      },
      ailmentDeleted(row){
        ailmentDeleted(row).then((res)=>{
          console.log(res.data)
          this.ailmentSelect()
        })
      }
    }
  }
</script>

<style scoped></style>
